﻿namespace Jhong.FunMVCBlog.Admin.Controllers
{
    using Jhong.FunMVC;
    using Jhong.FunMVCBlog.Core.Data;
    using Jhong.FunMVCBlog.Core.Enum;

    public abstract class BaseController : Controller
    {
        protected ActionResult AjaxResult(bool isSuccess, string msg = "", object data = null)
        {
            var model = new AjaxModel(isSuccess, msg, data);
            return Json(model, true);
        }

        private class AjaxModel
        {
            public bool IsSuccess { get; private set; }

            public string Msg { get; private set; }

            public object Data { get; private set; }

            public AjaxModel(bool isSuccess, string Msg, object data)
            {
                this.IsSuccess = isSuccess;
                this.Msg = Msg;
                this.Data = data;
            }
        }

        public override void OnException(ExceptionContext context)
        {
            new LogData().AddLog(LogType.Exception, LogFrom.Admin, context.Exception, context.Request.Uri.AbsoluteUri, context.Request.Method, context.Request.RemoteIpAddress);
        }
    }
}